import cPickle as pickle
import re
# 00FF00->finish..1   FF4500->unfinish..0
pattern = '(.*)#(\d)\s(.*)'
def getname():  #get all name
	x = open('All_raw.txt','r')
	f = x.readlines()
	allname = []
	for i in range(0,len(f),5):
		allname.append(re.match(pattern,f[i]).group(1))
	xp = open('all.pkl','wb')
	pickle.dump(allname,xp)
	xp.close()
	x.close()
def getlabels():# get label-->[0,raw_label,translate,re_translate]
	x = open('All_raw.txt','r')
	y = open('All_resultBD.txt')
	f  = x.readlines()
	h = y.readlines()
	for i in range(0,len(f),5):
		xp = open('raw_labels/'+re.match(pattern,f[i]).group(1)+'.pkl','wb')
		allname = []
		for j in range(0,5):
			allname.append([j,re.match(pattern,f[i+j]).group(3),re.match(pattern,h[i+j]).group(3)])
			print i+j
		if i==0:
			neighbor = [0,re.match(pattern,f[i+5]).group(1)]
		elif i==(len(f)-5):
			neighbor = [re.match(pattern,f[i-5]).group(1),0]
		else:
			neighbor = [re.match(pattern,f[i-5]).group(1),re.match(pattern,f[i+5]).group(1)]
		pickle.dump({'data':allname,'neighbor':neighbor},xp)
		xp.close()
	x.close()
	y.close()
def getaready():
	x = open('train.txt','r')
	xr = x.readlines()
	for i in range(0,len(xr),5):
		y = open('re_labels/'+re.match(pattern,xr[i]).group(1)+'.pkl','wb')
		alldata = []
		for j in range(0,5):
			print i,j
			alldata.append([j,re.match(pattern,xr[i+j]).group(3)])
			pass
		pickle.dump(alldata,y)
		y.close()
		pass
	x.close()
	pass
getaready()
# getname()
# getlabels()